<template>
	<div class="alertBox moneyRuleBox">
		<div class="alertBk"></div>
		<div class="wordBox">
			<div class="alertHead">
				<p class="tittle" v-text="title"></p>
				<div class="myClose" @click="closeMoneyRule">
					<img src="~_assets/close.png" class="myClose" />
				</div>
			</div>
			<div class="alertBody">
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>奖项名称:</p>
					<input @blur="checkName" minlength=2 maxlength=30 :disabled="isDetail" type="text" class="alertInput" placeholder="请输入奖项名称" v-model.trim="awardsName"/>
					<span class="checkTxt" v-show="diffAwardsName" v-text="diffText" style="right:12%"></span>
				</div>
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>奖项类型:</p>
					<el-radio v-model="couponType" label="992010" :disabled="isDetail">优惠券</el-radio>
					<el-radio v-model="couponType" label="992020" :disabled="isDetail">红包</el-radio>
					<span class="checkTxt" v-show="diffCouponType" v-text="diffText" style="right:52%"></span>
				</div>
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>奖项模式:</p>
					<el-radio v-model="discountsPattern" label="0" :disabled="isDetail">固定金额</el-radio>
					<el-radio v-model="discountsPattern" label="1" :disabled="isDetail">浮动金额</el-radio>
					<span class="checkTxt" v-show="diffDiscountsPattern" v-text="diffText" style="right:47%"></span>
				</div>
				<div class="changeDiv" v-show="showCouponDiv">
					<p class="alertText"><sup>*</sup>减免场景:</p>
					<!-- <el-radio v-model="reductionScenes" label="984001">全账单</el-radio> -->
					<el-radio v-model="reductionScenes" label="984002" :disabled="isDetail">服务费</el-radio>
					<el-radio v-model="reductionScenes" label="984003" disabled>停车账单</el-radio>
					<el-radio v-model="reductionScenes" label="984004" disabled>占位费</el-radio>
					<span class="checkTxt" v-show="diffReductionScenes" v-text="diffText" style="right:37%"></span>
				</div>
				<div class="changeDiv" v-show="showCouponFixed">
					<p class="alertText"><sup>*</sup>减免设置:</p>
					<p class="unit">满</p>
					<el-input placeholder="" v-model.trim="settingFullMoney" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<p class="unit">减</p>
					<el-input placeholder="" v-model.trim="settingReduceMoney" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<span class="checkTxt" v-show="diffMoney" v-text="diffText" style="right:30%"></span>
				</div>
				<div class="changeDiv" v-show="showCouponFloat">
					<p class="alertText"><sup>*</sup>减免设置:</p>
					<p class="unit">满</p>
					<el-input placeholder="" v-model.trim="settingFullMoney" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<p class="unit">减</p>
					<el-input placeholder="Min" v-model.trim="inputMin" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<p class="unit">至</p>
					<el-input placeholder="Max" v-model.trim="inputMax" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<span class="checkTxt" v-show="diffSettingReduceMoney" v-text="diffText" style="right:44%"></span>
				</div>
				<div class="changeDiv" v-show="showFixedRed">
					<p class="alertText"><sup>*</sup>红包金额:</p>
					<el-input placeholder="" v-model.trim="redMoney" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<p class="unit">元</p>
					<span class="checkTxt" v-show="diffRedMoney" v-text="diffText" style="right:49%"></span>
				</div>
				<div class="changeDiv" v-show="showFloatRed">
					<p class="alertText"><sup>*</sup>红包金额:</p>
					<el-input placeholder="Min" v-model.trim="inputMin" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<p class="unit">至</p>
					<el-input placeholder="Max" v-model.trim="inputMax" class="setInput" clearable :disabled="isDetail">
					</el-input>
					<span class="checkTxt" v-show="diffRedMoney" v-text="diffText" style="right:38%"></span>
				</div>
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>单次发放:</p>
					<el-input v-model.trim="singleIssue" class="setInput" :disabled="isDetail" maxlength="2">
					</el-input>
					<p class="unit">张</p>
					<span class="checkTxt" v-show="diffIsSingleIssue" v-text="diffText" style="right:44%"></span>
				</div>
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>投放数量:</p>
					<el-checkbox v-model="isNumLimit" :disabled="isDetail">限制</el-checkbox>
					<el-input v-model.trim="putNumber" class="setInput" :disabled="!isNumLimit || isDetail" maxlength="5">
					</el-input>
					<p class="unit">张</p>
					<span class="checkTxt" v-show="diffIsNumLimit" v-text="diffText" style="right:44%"></span>
				</div>
				<div class="changeDiv" v-show="isShowTimeArr">
					<p class="alertText"><sup>*</sup>使用时段:</p>
					<el-checkbox-group v-model="useTimeArr">
						<el-checkbox label="4" :disabled="isDetail">峰时</el-checkbox>
						<el-checkbox label="2" :disabled="isDetail">平时</el-checkbox>
						<el-checkbox label="1" :disabled="isDetail">谷时</el-checkbox>
					</el-checkbox-group>
					<span class="checkTxt" v-show="diffUseType" v-text="diffText" style="right:43%"></span>
				</div>
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>中奖概率:</p>
					<el-input placeholder="" @blur="checkNumer($event,6,0,1,'winningProbability')" v-model.trim="winningProbability" class="setInput" :disabled="isDetail">
					</el-input>/100000
					<span class="checkTxt" v-show="diffWin" v-text="diffText" style="right:50%"></span>
				</div>
				<!-- <div class="changeDiv">
					<p class="alertText"><sup>*</sup>赠送次数:</p>
					<el-radio v-model="giveTypeType" label="0" :disabled="isDetail">不限</el-radio>
					<el-radio v-model="giveTypeType" label="1" :disabled="isDetail">限制</el-radio>
					<el-select v-model="giveTypeType2" class="setSelect" :disabled="giveType == 0 || isDetail">
						<el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
					<el-input @blur="checkNumer($event,2,0,1,'giveNumber')" placeholder="" v-model.trim="giveNumber" class="setInput" clearable :disabled="giveType == 0 || isDetail">
					</el-input>
					<p class="unit">次</p>
					<span class="checkTxt" v-show="diffGiveType" v-text="diffText" style="right:14%"></span>
				</div> -->
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>有效期限:</p>
					<el-radio v-model="effectiveType" label="0" :disabled="isDetail">日期</el-radio>
					<el-date-picker :disabled="isDetail" value-format="yyyy-MM-dd" v-model="effectiveDeadline" type="date" placeholder="请选择日期" align="right" :picker-options="pickerOptions0">
					</el-date-picker>
					<el-radio v-model="effectiveType" label="1" :disabled="isDetail">天数</el-radio>
					<el-input placeholder="" v-model.trim="days" class="setInput" clearable :disabled="effectiveType == 0 ||isDetail" maxlength="3">
					</el-input>
					<p class="unit">天</p>
					<span class="checkTxt" v-show="diffEffectiveType" v-text="diffText" style="right:5%"></span>
				</div>
				<div class="changeDiv">
					<p class="alertText"><sup>*</sup>可用站点:</p>
					<div class="butInfoMes edit" :disabled="isDetail" @click="showStationDialog(1)" v-show="!isDetail">选择电站</div>
					<p class="seeStation" @click="showStationDialog(0)">查看电站</p>
					<span class="checkTxt" v-show="diffStation" v-text="diffText" style="right:52%"></span>
				</div>
				<div class="alertBut">
					<button class="isFalse" @click="closeMoneyRule(0)">取消</button>
					<button class="isTrue" @click="closeMoneyRule(1)" v-show="!isDetail">确认</button>
				</div>
			</div>
		</div>
		<PowerStation v-if="showStation" @closeStation="closeStation" :type="type" :ids="activityGroup" :seeStation="seeStation"></PowerStation>
	</div>
</template>

<script>
let timeType = {
  "3": "峰时",
  "2": "平时",
  "1": "谷时"
};
import { time } from "_config/common.js";
import {
  ADD_RED_PACKAGE_OR_COUPONRULE,
  UPDATE_RED_PACKAGE_OR_COUPON_RULE,
  FIND_RED_PACKAGE_OR_COUPON_RULE_BY_ID
} from "@/config/url";
import Bus from "@/bus.js";
import PowerStation from "_components/PowerStation";
import { publicVM } from "_config/public.js";

export default {
  mixins: [publicVM],
  components: {
    PowerStation
  },
  props: ["prizeID", "leng", "obj", "btnType", "giftID", "pos"],
  data() {
    return {
      showStation: false,
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      couponRadio: "1",
      input2: "",
      value2: "",
      checked1: "",
      checked2: "",
      checked3: "",
      checked4: "",
      redMoney: "",
      redMin: "",
      redMax: "",
      // item:sessionStorage.getItem('repeatRecord') == 1?null: this.obj,
      item: null,
      activityGroup: null,
      options2: [
        {
          value: "1",
          label: "活动周期"
        },
        {
          value: "2",
          label: "每日"
        }
      ],

      showCouponDiv: true,
      // showRedDiv: false,
      showCouponFixed: true,
      showCouponFloat: false,
      showFixedRed: false,
      showFloatRed: false,
      repeatRecord: sessionStorage.getItem("repeatRecord"), //活动复录：0 初录，1 复录
      activityCode: sessionStorage.getItem("activityCode"), //活动code
      lotteryId: null, //领劵id
      awardsName: null, //奖项名称
      couponType: "992010", //优惠券类型：（ 992010 优惠券  992020红包）
      discountsPattern: "0", //优惠模式：0 固定金额，1 浮动金额
      reductionScenes: "984002", //减免场景：全账单 984001，984002 服务费，984003 停车账单，984004 占位费
      settingFullMoney: null, //减免设置的满足金额（列:满20减2）
      settingReduceMoney: null, //减免设置的扣除金额（列:满20减2） 或 是浮动金额（满20减 min~max）
      inputMin: null, //浮动金额最小值
      inputMax: null, //浮动金额最大值
      putNumber: "0", //投放数量：0 代表不限制 ，0之上之上代表限定的张数
      useType: 0, //使用时段：3:峰时 2：平时 1：谷时
      useTimeArr: [], //使用时段数组
      winningProbability: "100000", //中奖概率
      singleIssue: '',//单次发放
      // giveNumber: "0", //赠送次数: 0 不限，0之上限制的次数（限制）
      giveType: "0", // 赠送限制的类型：1 活动周期，2 每日
      effectiveType: "0", //有效期限类型：0 日期，1 天数
      type: {},
      redMoney: null,
      effectiveDeadline: null, //有效期限
      redPackageMoney: null, //红包金额
      usableSite: [], //可用站点（站点id）
      couponSort: null, //排序
      days: null, //天数
      isIdentical: null, //初录复录是否一致: 0 一致，1 不一致
      diffText: "与初录不一致",
      isNumLimit: false,
      isDetail: false,
      url: ADD_RED_PACKAGE_OR_COUPONRULE,
      diffAwardsName: false,
      diffCouponType: false,
      diffDiscountsPattern: false,
      diffReductionScenes: false,
      diffMoney: false,
      diffRedMoney: false,
      diffIsNumLimit: false,
      diffIsSingleIssue: false,
      diffUseType: false,
      diffWin: false,
      diffGiveType: false,
      diffEffectiveType: false,
      diffStation: false,
      diffSettingReduceMoney: false,
      firstDate: this.$store.getters.getFirstCouponData,
      secDate: this.$store.getters.getSecCouponData,
      // giveTypeType: "0", //赠送次数
      // giveTypeType2: "1", //赠送类型
      title: "", //标题
      seeStation:true,//查看电站
      isShowTimeArr: true,
    };
  },
  created() {
    if (this.btnType == "1") {
      //修改
      this.url = UPDATE_RED_PACKAGE_OR_COUPON_RULE;
      this.title = "修改奖项";
      this.isDetail = false;
    } else if (this.btnType == "3") {
      //新增
      this.url = ADD_RED_PACKAGE_OR_COUPONRULE;
      this.title = "新建奖项";
      this.isDetail = false;
    } else if (this.btnType == "2") {
      //详情
      this.title = "奖项详情";
      this.isDetail = true;
    }
    if (this.item) {
      this.useType = this.getUserType(this.obj.useType);
    }
    this.chooseType();
  },
  mounted() {
    if (this.btnType != 3) {
      this.getFirstData();
    }
  },
  watch: {
    inputMin(val) {
      this.diffRedMoney =
        this.repeatRecord == 1 &&
        this.item &&
        val != this.item.settingReduceMoney.split(",")[0];
    },
    inputMax(val) {
      if (val < this.inputMin) {
        // this.inputMax = null
      }
      this.diffRedMoney =
        this.repeatRecord == 1 &&
        this.item &&
        val != this.item.settingReduceMoney.split(",")[1];
    },
    giveTypeType(val) {
      if (val == 0) {
        this.giveType = 0;
      } else {
        this.giveType = this.giveTypeType2;
      }
    },
    useTimeArr(val) {
      val = this.sortType(val);
      this.diffUseType =
        this.repeatRecord == 1 &&
        this.item &&
        val.toString() != this.item.useType;
    },
    couponType(val) {
      this.chooseType();
      if (this.repeatRecord == 1) {
        this.diffCouponType =
          this.repeatRecord == 1 && this.item && val != this.item.couponType;
      }
    },
    couponRadio() {
      if (this.couponRadio == 2) {
        this.showCouponFixed = false;
        this.showCouponFloat = true;
      } else {
        this.showCouponFixed = true;
        this.showCouponFloat = false;
      }
    },
    discountsPattern(val) {
      this.chooseType();
      this.diffDiscountsPattern =
        this.repeatRecord == 1 &&
        this.item &&
        val != this.item.discountsPattern;
    },
    awardsName(val) {
      this.diffAwardsName =
        this.repeatRecord == 1 && this.item && val != this.item.awardsName;
    },
    singleIssue(val) {
      this.diffIsSingleIssue =
        this.repeatRecord == 1 && this.item && val != this.item.singleIssue;
    },
    reductionScenes(val) {
      this.diffReductionScenes =
        this.repeatRecord == 1 && this.item && val != this.item.reductionScenes;
    },
    settingFullMoney(val) {
      if(this.settingReduceMoney){
        if(val*1 < this.settingReduceMoney*1){
          this.settingReduceMoney = null
          this.$message({
            message: "满减金额要大于优惠金额",
            type: "warning"
          });
        }
      }
      this.diffMoney =
        this.repeatRecord == 1 &&
        this.item &&
        val != this.item.settingFullMoney;
    },
    settingReduceMoney(val) {
      if (val * 1 > this.settingFullMoney * 1) {
        this.$message({
          message: "优惠金额要小于满减金额",
          type: "warning"
        });
        this.settingReduceMoney = null;
      }
      if(this.item){
        if (this.item.couponType == "992010") {
          this.diffMoney =
            this.repeatRecord == 1 &&
            this.item &&
            val != this.item.settingReduceMoney;
        } else if (this.item.couponType == "992020") {
          this.diffRedMoney =
            this.repeatRecord == 1.01 &&
            this.item &&
            val != this.item.settingReduceMoney;
        }
      }
    },
    redMoney(val) {
      this.diffRedMoney =
        this.repeatRecord == 1 &&
        this.item &&
        val != this.item.settingReduceMoney;
    },
    isNumLimit(val) {
      if (val) {
        if(this.putNumber > 0){
          
          }else{
          this.putNumber = 10;

        }
      } else {
        this.putNumber = 0;
      }
    },
    putNumber(val) {
      this.diffIsNumLimit =
        this.repeatRecord == 1 && this.item && val != this.item.putNumber;
    },
    useType(val) {
      this.diffUseType =
        this.repeatRecord == 1 &&
        this.item &&
        val.toString() != this.item.useType;
    },
    winningProbability(val) {
      this.diffWin =
        this.repeatRecord == 1 &&
        this.item &&
        val != this.item.winningProbability;
    },
    giveType(val) {
      if (val == 0) {
        this.giveNumber = 0;
        this.giveTypeType = '0'
      } else {
        this.giveTypeType = '1'
        this.giveTypeType2 = val+''
        this.giveNumber = this.item.giveNumber || 1;
      }
      if (this.item) {
        if(this.repeatRecord == 1){
          if (val != this.item.giveType) {
            this.diffGiveType = true;
          } else {
            this.diffGiveType = false;
            if (val > 0) {
              this.diffGiveType = this.giveNumber != this.item.giveNumber;
            }
          }
        }
      }
    },
    effectiveType(val) {
      if (val == 0) {
        this.days = null;
        this.diffEffectiveType =
          this.repeatRecord == 1 &&
          this.item &&
          this.effectiveDeadline.toString() != this.item.effectiveDeadline;
      } else {
        this.effectiveDeadline = null;
        if(!this.checkNum1(Number(this.item.effectiveDeadline))){
            this.days = 1
        }else{
          this.days = this.item.effectiveDeadline;
        }
        this.diffEffectiveType =
          this.repeatRecord == 1 &&
          this.item &&
          this.effectiveDeadline.toString() != this.item.effectiveDeadline;
      }
      if (this.item) {
        if (val != this.item.effectiveType) {
          this.diffEffectiveType = true;
        } else {
          this.diffEffectiveType = false;
        }
      }
    },
    effectiveDeadline(val) {
      this.diffEffectiveType =
        this.repeatRecord == 1 &&
        this.item &&
        val.toString() != this.item.effectiveDeadline;
    },
    days(val) {
      this.diffEffectiveType =
        this.repeatRecord == 1 &&
        this.item &&
        val.toString() != this.item.effectiveDeadline;
    },
    usableSite(val) {
      this.diffStation =
        this.repeatRecord == 1 && this.item && val != this.item.usableSite;
    }
  },
  methods: {
    closeStation(data) {
      if (data) {
        let ids = [];
        this.usableSite = [];
        for (let item of data.data) {
          this.usableSite.push(item.id);
        }
        this.usableSite = this.usableSite.toString();
      }
      this.showStation = false;
    },
    checkName(e) {
      let title = $(e.target).val();
      if (title.length < 2) {
        this.$message({
          message: "最少输入2个字符",
          type: "warning"
        });
      }
    },
    getFirstData() {
      let that = this;
      let id = this.firstDate[this.pos - 1].id;
      this.$fetch(FIND_RED_PACKAGE_OR_COUPON_RULE_BY_ID, {
        couponRuleId: id
      })
        .then(res => {
          if (res.status == 1) {
            this.item = res.data;
            let data = res.data;
            if (res.data) {
              if (this.repeatRecord == 0) {
                this.updataData(data);
              } else {
                if (that.$route.path != "/settingIndex/activityDone") {
                  this.getSecData();
                  this.diffUseType = true;
                } else {
                  this.updataData(data);
                }
              }
            }
          } else {
            this.$message({
              message: res.data,
              type: "warning"
            });
          }
        })
        .catch(err => {
          console.log(err);
          this.$message({
            message: "获取失败",
            type: "warning"
          });
        });
    },
    getSecData() {
      let id = this.secDate[this.pos - 1].id;
      this.$fetch(FIND_RED_PACKAGE_OR_COUPON_RULE_BY_ID, {
        couponRuleId: id
      })
        .then(res => {
          if (res.status == 1) {
            let data = res.data;
            if (res.data) {
              if (this.repeatRecord == 1) {
                this.updataData(data);
              }
            }
          } else {
            this.$message({
              message: res.data,
              type: "warning"
            });
          }
        })
        .catch(err => {
          console.log(err);
          this.$message({
            message: "获取失败",
            type: "warning"
          });
        });
    },
    updataData(data) {
      if (data.awardsName) {
        this.awardsName = data.awardsName;
        this.couponType = data.couponType;
        this.discountsPattern = data.discountsPattern + "";
        this.reductionScenes = data.reductionScenes;
        this.settingFullMoney = data.settingFullMoney;
        if (/,/.test(data.settingReduceMoney)) {
          let arr = data.settingReduceMoney.split(",");
          this.inputMin = arr[0];
          this.inputMax = arr[1];
        } else {
          this.settingReduceMoney = data.settingReduceMoney;
          this.redMoney = data.settingReduceMoney;
        }
        this.putNumber = data.putNumber;
        this.winningProbability = data.winningProbability;
        this.giveNumber = data.giveNumber;
        if (data.giveNumber == 0) {
          this.giveType == "0";
        } else {
          this.giveType = data.giveType;
        }
        if (data.putNumber > 0) {
          this.isNumLimit = true;
        } else {
          this.isNumLimit = false;
        }
        this.effectiveType = data.effectiveType + "";
        this.effectiveDeadline = data.effectiveDeadline;
        // this.redPackageMoney = data.redPackageMoney
        this.usableSite = data.usableSite;
        this.singleIssue = data.singleIssue;
        this.couponSort = data.couponSort || this.leng * 1 + 1;
        // this.useType = data.useType && data.useType.split(',')
        // this.useTimeArr = this.getUserType(data.useType);
        if(data.useType != null){
          this.useTimeArr = data.useType.split(",");;
        }
      }
      if (this.repeatRecord == 1) {
        this.diffCouponType =
          this.repeatRecord == 1 &&
          this.item &&
          this.item.couponType != "992010";
        this.diffDiscountsPattern =
          this.repeatRecord == 1 &&
          this.item &&
          this.item.discountsPattern != "0";
        this.diffIsNumLimit =
          this.repeatRecord == 1 &&
          this.item &&
          this.item.putNumber != this.putNumber;
        this.diffEffectiveType =
          this.repeatRecord == 1 &&
          this.item &&
          this.item.effectiveDeadline != "";
        this.diffStation = this.repeatRecord == 1 && this.item && this.item.usableSite != [];
      }
    },
    showStationDialog(type) {//type 1选择电站0查看电站
      if (type == 1) {
        this.activityGroup = null;
        this.showStation = true;
        this.seeStation = false
        this.type = {
          type:1,
          value:'chose'
        }
      } else {
        this.seeStation = true
        this.activityGroup = this.usableSite;
        if (this.activityGroup.length > 0) {
          this.showStation = true;
          this.type = {
            type:1,
            value:'see'
          }
        }
      }
    },
    closeMoneyRule(type) {
      if (type == 1) {
        
        if (this.giveType == 0) {
          this.giveNumber = "0";
        }

        if (!this.isNumLimit) {
          this.putNumber = "0";
        }

        //优惠金额
        if(this.couponType == '992020'){//红包金额
          if(this.discountsPattern == '1'){//浮动
            if(this.inputMax == '' ||this.inputMax == null || this.inputMin == '' || this.inputMin == null){
              this.$message.error('红包金额不能为空');
              return;
            }else{
              if(!this.checkNum(Number(this.inputMax)) || !this.checkNum(Number(this.inputMin))){
                  this.$message.error('红包金额只能为数字');
                  return;
              }else{
                if(Number(this.inputMax) <= Number(this.inputMin)){
                  this.$message.error('红包最大金额要大于最小金额');
                  return;
                }
              }
            }
          }else if(this.discountsPattern == '0'){//固定
            if(this.redMoney == '' || this.redMoney == null){
              this.$message.error('红包金额不能为空');
              return;
            }else{
              if(!this.checkNum(Number(this.redMoney))){
                  this.$message.error('红包金额只能为数字');
                  return;
              }
            }
          }
        }else if(this.couponType == '992010'){//优惠券
          if(this.discountsPattern == '1'){//浮动
            if(this.settingFullMoney == '' || this.settingFullMoney == null || this.inputMin == '' || this.inputMin == null || this.inputMax == '' || this.inputMax == null){
              this.$message.error('减免金额不能为空');
              return;
            }else{
              if(!this.checkNum(Number(this.settingFullMoney)) || !this.checkNum(Number(this.inputMax)) || !this.checkNum(Number(this.inputMin))){
                  this.$message.error('减免金额只能为数字');
                  return;
              }else{
                if(Number(this.inputMax) <= Number(this.inputMin)){
                  this.$message.error('减免最大金额要大于最小金额');
                  return;
                }
                if(Number(this.inputMax) > Number(this.settingFullMoney)){
                  this.$message.error('最大金额不得高于使用门槛');
                  return;
                }
              }
            }
          }else if(this.discountsPattern == '0'){//固定
            if(this.settingFullMoney == '' || this.settingFullMoney == null || this.settingReduceMoney == '' || this.settingReduceMoney == null){
              this.$message.error('减免金额不能为空');
              return;
            }else{
              if(!this.checkNum(Number(this.settingFullMoney)) || !this.checkNum(Number(this.settingReduceMoney))){
                  this.$message.error('减免金额只能为数字');
                  return;
              }
            }
          }
        }
        if(this.singleIssue == '' || this.singleIssue == null){
           this.$message.error('请输入单次发放数量');
           return;
        }else if(!this.checkNum1(Number(this.singleIssue))){
            this.$message.error('单次发放数量只能为不含小数的数字');
            return;
        }
        if(this.isNumLimit == true){
          if(this.putNumber == '' || this.putNumber == null){
            this.$message.error('请输入投放数量');
            return;
          }else if(!this.checkNum1(Number(this.putNumber))){
            this.$message.error('投放数量只能为不含小数的数字');
            return;
          }
        }
        //使用时段
        if (this.useTimeArr.length > 0) {
          let num = 0;
          for (let i = 0; i < this.useTimeArr.length; i++) {
            num += this.useTimeArr[i] * 1;
          }
          this.useType = num;
        }
        if (this.couponType == "992010") {
          if(this.useType <=0){
            this.$message({
              message: `请选择使用时段`,
              type: "warning"
            });
            return;
          }
        }
        //有效日期
        if (this.effectiveType == 0) {
          if (this.effectiveDeadline != null) {
            this.effectiveDeadline = this.effectiveDeadline && this.effectiveDeadline.toString();
          } else {
            this.$message.error('请选择有效日期');
            return;
          }
        } else {
          if(this.days == '' || this.days == null){
            this.$message.error('天数不能为空');
            return;
          }else{
            if(!this.checkNum(Number(this.days))){
              this.$message.error('天数只能为数字');
              return;
            }else{
              this.effectiveDeadline = this.days
            }
          }
        }
        let id = this.$store.getters.getCurrentLottery;
        let param = {
          activityCode: this.activityCode,
          lotteryId: id,
          awardsName: this.awardsName,
          couponType: this.couponType,
          discountsPattern: this.discountsPattern,
          reductionScenes: this.reductionScenes,
          settingFullMoney: this.settingFullMoney,
          settingReduceMoney: this.settingReduceMoney,
          putNumber: this.putNumber,
          useType: this.useType,
          winningProbability: this.winningProbability,
          giveNumber: this.giveNumber,
          effectiveType: this.effectiveType,
          effectiveDeadline: this.effectiveDeadline,
          redPackageMoney: null,
          usableSite: this.usableSite,
          couponSort: this.couponSort,
          inputMax: this.inputMax,
          inputMin: this.inputMin,
          repeatRecord: this.repeatRecord,
          singleIssue: this.singleIssue
        };
        if(this.giveNumber > 0){
          param.giveType = this.giveTypeType2
        }else{
          param.giveType = this.giveType
        }
        if (this.btnType == "1") {
          //修改
          param.id = this.giftID;
          param.couponSort = this.couponSort;
        } else if (this.btnType == "3") {
          param.couponSort = this.leng * 1 + 1;
        }
        if (this.repeatRecord == 0) {
          param.isIdentical = 0;
        } else {
          if (
            this.diffAwardsName ||
            this.diffCouponType ||
            this.diffDiscountsPattern ||
            this.diffReductionScenes ||
            this.diffMoney ||
            this.diffSettingReduceMoney ||
            this.diffIsNumLimit ||
            this.diffUseType ||
            this.diffWin ||
            this.diffGiveType ||
            this.diffEffectiveType ||
            this.diffStation ||
            this.diffIsSingleIssue
          ) {
            param.isIdentical = 1;
          } else {
            param.isIdentical = 0;
          }
        }
        if (this.awardsName && this.putNumber && this.winningProbability) {
          if(this.awardsName.length < 2){
            this.$message({
              message: "最少输入2个字符",
              type: "warning"
            });
            return;
          }
          if (this.usableSite.length == 0) {
            this.$message({
              message: "请选择电站",
              type: "warning"
            });
            return;
          }
          if(this.discountsPattern == 1){
            if(this.inputMin == null || this.inputMax == null){
              this.$message({
                message: `优惠金额不能为空`,
                type: "warning"
              });
              return;
            }
          }
          if (this.couponType == "992010") {
            if (this.settingFullMoney) {
              if (this.discountsPattern == 1) {
                param.settingReduceMoney = `${this.inputMin},${this.inputMax}`;
              }
              this.addPrize(param);
            }
          } else if (this.couponType == "992020") {
            param.settingFullMoney = null;
            param.settingReduceMoney = this.redMoney;
            if (this.discountsPattern == 1) {
              param.settingReduceMoney = `${this.inputMin},${this.inputMax}`;
            }
            this.addPrize(param);
          } else {
            this.$message({
              message: "请写必填项",
              type: "warning"
            });
          }
        } else {
          this.$message({
            message: "请写必填项",
            type: "warning"
          });
        }
      } else {
        this.$emit("closeMoneyRule");
      }
    },
    addPrize(param) {
      this.$post(this.url, param)
        .then(res => {
          if (res.status == 1) {
            if (res.data == "修改奖项成功") {
              Bus.$emit("refreshList");
              this.$emit("closeMoneyRule");
            } else {
              param.id = res.data;
              Bus.$emit("addItem", {
                param: param,
                id: res.data
              });
              Bus.$emit("refreshCoupon", this.$store.getters.getCurrentLottery);
              this.$emit("closeMoneyRule");
            }
          } else {
            this.$message({
              message: res.data,
              type: "warning"
            });
          }
        })
        .catch(err => {
          console.log(err);
          this.$message({
            message: "必填项不能为空",
            type: "warning"
          });
        });
    },
    chooseType() {
      if (this.couponType == 992010) {
        this.showCouponDiv = true;
        this.showFixedRed = false;
        this.showFloatRed = false;
        this.redPackageMoney = null;
        this.isShowTimeArr = true;
        if (this.discountsPattern == 0) {
          this.showCouponFixed = true;
          this.showCouponFloat = false;
        } else {
          this.showCouponFixed = false;
          this.showCouponFloat = true;
        }
      } else {
        this.settingFullMoney = null;
        this.settingReduceMoney = null;
        // this.reductionScenes = null
        this.showCouponDiv = false;
        this.showCouponFixed = false;
        this.showCouponFloat = false;
        this.isShowTimeArr = false;
        if (this.discountsPattern == 0) {
          this.showFixedRed = true;
          this.showFloatRed = false;
        } else {
          this.showFixedRed = false;
          this.showFloatRed = true;
        }
      }
    }
    // getUserType(data){
    // 	let arr = []
    // 	for(let item of data.split(',')){
    // 		arr.push(item)
    // 	}
    // 	return arr
    // }
  }
};
</script>

<style lang="less">
.moneyRuleBox {
  .wordBox {
    width: 45%;
  }
  .changeDiv {
    width: 92%;
    position: relative;
  }
  .alertText {
    width: 14%;
  }
  .setInput {
    width: 15%;
  }
  .unit {
    color: #2d3343;
    margin-left: 0.05rem;
  }
  .el-radio,
  .el-checkbox,
  .edit {
    margin-left: 0.08rem;
    margin-right: 0.08rem;
  }
  .seeStation {
    color: #2d3343;
    text-decoration: underline;
  }
}
</style>